package com.punai.gk.controller;

import com.punai.common.annotation.Log;
import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.core.page.TableDataInfo;
import com.punai.common.enums.BusinessType;
import com.punai.gk.domain.GkTemplate;
import com.punai.gk.service.IGkTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 归口模板Controller
 * 
 * @author zxw_
 * @date 2023-01-06
 */
@RestController
@RequestMapping("/gk/template")
public class GkTemplateController extends BaseController
{
    @Autowired
    private IGkTemplateService gkTemplateService;

    /**
     * 查询归口模板列表
     */
//    @PreAuthorize("@ss.hasPermi('gk:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(GkTemplate gkTemplate)
    {
        startPage();
        List<GkTemplate> list = gkTemplateService.selectGkTemplateList(gkTemplate);
        return getDataTable(list);
    }

    /**
     * 获取归口模板详细信息
     */
//    @PreAuthorize("@ss.hasPermi('gk:template:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(gkTemplateService.selectGkTemplateById(id));
    }

    /**
     * 获取归口数据详细信息
     */
//    @PreAuthorize("@ss.hasPermi('gk:template:query')")
    @GetMapping(value = "/getTemplateId/{gkName}/{gkType}")
    public AjaxResult getTemplateId(@PathVariable("gkName") String gkName,@PathVariable("gkType") String gkType)
    {
        return AjaxResult.success("获取成功",gkTemplateService.getTemplateId(gkName,gkType));
    }


//    @PreAuthorize("@ss.hasPermi('gk:template:query')")
    @GetMapping(value = "/getTemplateColumn/{templateId}")
    public AjaxResult getTemplateId(@PathVariable("templateId") String templateId)
    {
        return AjaxResult.success(gkTemplateService.getTemplateColumn(templateId));
    }

//    @PreAuthorize("@ss.hasPermi('gk:template:query')")
    @GetMapping(value = "/getTemplateLinkFeeType/{templateId}")
    public AjaxResult getTemplateLinkFeeType(@PathVariable("templateId") String templateId)
    {
        return AjaxResult.success(gkTemplateService.getTemplateLinkFeeType(templateId));
    }



    /**
     * 新增归口模板
     */
    @PreAuthorize("@ss.hasPermi('gk:template:add')")
    @Log(title = "归口模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GkTemplate gkTemplate)
    {
        return toAjax(gkTemplateService.insertGkTemplate(gkTemplate));
    }

    /**
     * 修改归口模板
     */
    @PreAuthorize("@ss.hasPermi('gk:template:edit')")
    @Log(title = "归口模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GkTemplate gkTemplate)
    {
        return toAjax(gkTemplateService.updateGkTemplate(gkTemplate));
    }

    /**
     * 删除归口模板
     */
    @PreAuthorize("@ss.hasPermi('gk:template:remove')")
    @Log(title = "归口模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        return toAjax(gkTemplateService.deleteGkTemplateById(id));
    }
}
